package com.youpai.platform.vulture.common.util;

import com.youpai.platform.vulture.common.entity.AccessMessage;
import com.youpai.platform.vulture.common.entity.Header;
import com.youpai.platform.vulture.common.enums.ClientCommandEnum;
import com.youpai.platform.vulture.common.enums.HeaderTypeEnum;
import com.youpai.platform.vulture.common.enums.MsgFlagEnum;
import com.youpai.platform.vulture.common.enums.ServerCommandEnum;
import java.util.ArrayList;
import java.util.List;

/**
 * @date: 2023/2/24 14:45
 * @author: Welles
 * @version: 1.0
 */
public class AccessMessageSupport {

    /**
     * 构造ping
     *
     * @return 心跳消息
     */
    public static AccessMessage buildPingMessage() {
        AccessMessage accessMessage = new AccessMessage();
        accessMessage.setFlag(MsgFlagEnum.HEART_BEAT_PONG.flag);
        return accessMessage;
    }

    /**
     * 构造pong
     *
     * @return pong
     */
    public static AccessMessage buildPongMessage() {
        AccessMessage accessMessage = new AccessMessage();
        accessMessage.setFlag(MsgFlagEnum.HEART_BEAT_PING.flag);
        return accessMessage;
    }

    /**
     * 构造普通命令消息
     *
     * @param clientCommandEnum 客户端命令
     * @param body 消息题
     * @return 消息
     */
    public static AccessMessage buildOrdinaryCmdMessage(ClientCommandEnum clientCommandEnum, String body) {
        AccessMessage accessMessage = new AccessMessage();
        Header header = new Header();
        List<Header> headerList = new ArrayList<>();
        headerList.add(header);
        header.setHeaderValue(HeaderTypeEnum.COMMAND)
                .setHeaderValue(clientCommandEnum.cmd);
        return accessMessage.setFlag(MsgFlagEnum.ORDINARY_MSG.flag)
                .setHeaderList(headerList)
                .setBody(body);
    }

    /**
     * 构造普通命令消息
     *
     * @param serverCommandEnum 服务端命令
     * @param body 消息题
     * @return 消息
     */
    public static AccessMessage buildOrdinaryCmdMessage(ServerCommandEnum serverCommandEnum, String body) {
        AccessMessage accessMessage = AccessMessage.build();
        Header header = Header.build();
        List<Header> headerList = new ArrayList<>();
        headerList.add(header);
        header.setHeaderValue(HeaderTypeEnum.COMMAND)
                .setHeaderValue(serverCommandEnum.cmd);
        return accessMessage.setFlag(MsgFlagEnum.ORDINARY_MSG.flag)
                .setHeaderList(headerList)
                .setBody(body);
    }
}
